﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNHASACH.DTO;
using QLNHASACH.BussinessLayer.ObjectBUS;

namespace QLNHASACH.PresentationLayer.Controls
{
    public partial class DoiMatKhauCtrl : UserControl
    {
        public DoiMatKhauCtrl()
        {
            InitializeComponent();
        }

        private void btThayDoi_Click(object sender, EventArgs e)
        {
                if (Utilitiles.User.MatKhau == Utilitiles.MaHoaMD5(txbMatKhauCu.Text))
                {
                    if (txbMatKhauMoi.Text == txbMatKhauMoiLai.Text)
                    {
                        if (NguoiDungBUS.ThayDoiMatKhau(Utilitiles.User.TenDangNhap, Utilitiles.MaHoaMD5(txbMatKhauMoi.Text)) == true)
                        {
                            MessageBox.Show("Đổi mật khẩu thành công.!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else MessageBox.Show("Hai mật khẩu không trùng nhau..!", "Thông báo", MessageBoxButtons.OK);
                }
                else MessageBox.Show("Mật khẩu cũ ko chính xác", "Thông báo", MessageBoxButtons.OK);
        }



        private void txbMatKhauCu_TextChanged(object sender, EventArgs e)
        {
            if (Utilitiles.User.MatKhau == Utilitiles.MaHoaMD5(txbMatKhauCu.Text))
            {
                pbTick2.Visible = true;
            }
            else pbTick2.Visible = false;
        }

        private void txbMatKhauMoiLai_TextChanged(object sender, EventArgs e)
        {
            if (txbMatKhauMoi.Text == txbMatKhauMoiLai.Text)
                pbTick3.Visible = true;
            else pbTick3.Visible = false;

        }
        public void ResetValue()
        {
            txbMatKhauCu.Text = "";
            txbMatKhauMoi.Text = "";
            txbMatKhauMoiLai.Text = "";
            pbTick2.Visible = false;
            pbTick3.Visible = false;
        }
        private void btThoat_Click(object sender, EventArgs e)
        {
            ResetValue();
        }
    }
}
